package com.gxuwz.prrs.service.impl;

import com.google.gson.reflect.TypeToken;
import com.gxuwz.prrs.bean.*;
import com.gxuwz.prrs.service.BaseService;
import com.gxuwz.prrs.utils.RequestUtils;
import okhttp3.FormBody;

import java.lang.reflect.Type;

import static com.gxuwz.prrs.service.impl.CheckRecordServiceImpl.getaBoolean;


/**
 * @author 张钧
 * @Description
 * @create 2023-05-24 上午 11:22
 */
public class PianoRoomServiceImpl implements BaseService<PianoRoom,PianoRoomQuery<PianoRoom>> {

	private PianoRoomQuery<PianoRoom> lastPage;


	@Override
	public Page<PianoRoom> page(PianoRoomQuery<PianoRoom> page) {
		if (page == null) {
			page = lastPage;
		} else {
			lastPage = page;
		}
		String url = "/piano/room/page?size=" + page.getSize()
				+ "&current=" + page.getCurrent()
				+ "&pianoRoomNo=" + page.getPianoRoomNo()
				+ "&openTime=" + page.getOpenTime();
		Type type = new TypeToken<CommonResponse<Page<PianoRoom>>>() {
		}.getType();
		CommonResponse<Page<PianoRoom>> response = RequestUtils.getRequest(url,type);
		if (response != null) {
			return response.getData();
		}
		return null;
	}

	public boolean appointmentPianoRoom(PianoRoomAppointment pianoRoomAppointment) {
		String url = "/piano/room/appoint";
		FormBody.Builder builder = new FormBody.Builder();
		builder.add("pianoRoomId", pianoRoomAppointment.getPianoRoomId());
		builder.add("appointmentTime", pianoRoomAppointment.getAppointmentTime());
		builder.add("openTime", lastPage.getOpenTime());
		return getaBoolean(builder, url);
	}
}
